/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fsflightplanner;

import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Matt
 */
public class Utils {

    public static ArrayList<String[]> parseDelimitedFile(String filePath, String delimiter) throws Exception {
        ArrayList<String[]> rows = new ArrayList<String[]>();
        Scanner scanner = new Scanner(new File(filePath));
        scanner.useDelimiter("(\\n|\\r|\\r\\n)");
        while (scanner.hasNext()) {
            rows.add(scanner.next().split(delimiter));
        }
        return rows;
    }

    public static String properCase(String s) {
        Pattern p = Pattern.compile("(^|\\W)([a-z])");
        Matcher m = p.matcher(s.toLowerCase());
        StringBuffer sb = new StringBuffer(s.length());
        while (m.find()) {
            m.appendReplacement(sb, m.group(1) + m.group(2).toUpperCase());
        }
        m.appendTail(sb);
        return sb.toString();
    }
}
